import { Component } from 'vue'
import { fileExtParser, type Filetype } from '@/utils'
import { Folder, DocumentText } from '@vicons/ionicons5'
import { Html5Outlined } from '@vicons/antd'
import { Json, Png, Jpg, DocumentUnknown, Websheet } from '@vicons/carbon'

const filetypeIconDict: { [key: Filetype]: Component } = {
  html: Html5Outlined,
  json: Json,
  png: Png,
  jpg: Jpg,
  txt: DocumentText,
  disp: Websheet,
  unknown: DocumentUnknown,
}

/**
 * 根据文件信息确定文件所用的图标
 * @param path 文件路径或文件名
 * @param isFolder 是否为文件夹
 */
export default function getFileIcon(path: string, isFolder = false): Component {
  let component: Component = Folder
  if (isFolder) return component
  const filetype = fileExtParser.filetype(path)
  component = filetypeIconDict[filetype]
  if (!component) component = DocumentUnknown
  return component
}
